<template>
  <div class="skill-wrap">
    <div class="chose-course-top">
      <div class="header-left">
        <span class="back-arrow" @click="closeHandle"></span>
      </div>
      <div class="course-title">
        考点解读
      </div>
      <div class="btn-group">
        <a :disabled="printDisabled" @click="print">打印</a>
      </div>
    </div>
    <div class="skill-content">
      <div class="skill-info" v-html="info.detail"></div>
    </div>
    <Timetips ref="timetips"></Timetips>
  </div>
</template>
<script>
import { grammarPoint, printData } from "@/services/reverse";
import { SUCCESS_CODE } from "@/utils/const";
import { mapState, mapMutations } from "vuex";
import Timetips from "@/components/Timetips";
import _ from "lodash";
export default {
  components: {
    Timetips
  },
  data() {
    return {
      info: {},
      printDisabled: false,
    };
  },
  computed: {
    ...mapState({
      reverseStatus: (state) => state.reverseStatus,
      grammarExplainVisible: (state) => state.grammarExplainVisible,
    }),
  },
  watch: {
    grammarExplainVisible: function(val) {
      if (val === true) {
        grammarPoint({
          ..._.pick(this.reverseStatus, ["chapters_id"]),
        }).then((res) => {
          if (res.code === SUCCESS_CODE) {
            this.info = res.data;
          }
        });
      }
    },
  },
  methods: {
    ...mapMutations(["setGrammarExplain"]),
    closeHandle() {
      this.setGrammarExplain(false);
    },
    print() {
      printData({
        curr_id: this.reverseStatus.curr_id,
        chapter_id: this.reverseStatus.chapters_id,
        type: 1,
      }).then((res) => {
        if (res.code === SUCCESS_CODE) {
          this.printInterval();
          this.$message.success("已提交打印,请到管理平台进行打印");
        } else {
          this.$message.error("您打印的过于频繁，请休息一下");
        }
      });
    },
    printInterval() {
      //倒计时
      let time = 60;
      this.printDisabled = true;
      let timer = setInterval(() => {
        if (time == 0) {
          clearInterval(timer);
          this.printDisabled = false;
        } else {
          this.printDisabled = true;
          time--;
        }
      }, 1000);
    },
  },
  created() {},
  mounted() {},
  beforeCreate() {},
  beforeMount() {},
  beforeUpdate() {},
  updated() {},
  beforeDestroy() {
    this.$refs.timetips.stopTimer();
    this.$refs.timetips.stopEndTimer();
  },
  destroyed() {},
  activated() {},
};
</script>
<style lang="less" scoped>
/* @import url(); 引入公共css类 */
.skill-wrap {
  position: fixed;
  z-index: 1999;
  background-color: #fff;
  width: 100%;
  top: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  .chose-course-top {
    display: flex;
    justify-content: space-between;
    position: relative;
    align-items: center;
    height: 80px;
    padding: 0 40px;
    background-color: #fff;
    .anticon {
      font-size: 24px; /* no */
    }
    .header-left {
      flex: 1;
      display: flex;
      align-items: center;
      justify-content: flex-start;
      .back-arrow {
        width: 30px;
        height: 27px;
        background-image: url("~assets/home/btn_back.png");
        background-size: 100%;
        cursor: pointer;
      }
    }

    .course-title {
      width: 100%;
      flex: 1;
      font-size: 20px;
      font-weight: 700;

      .check-title {
        color: #c7c7c7;
        padding: 0 15px;
      }
      .check__active {
        color: @primary-color;
        position: relative;
        &::after {
          content: "";
          position: absolute;
          width: 23px;
          height: 4px;
          background-color: @primary-color;
          bottom: -8px;
          left: 50%;
          transform: translateX(-50%);
        }
      }
    }
    .btn-group {
      flex: 1;
      display: flex;
      justify-content: flex-end;
      align-items: center;
      & > a {
        display: inline-block;
        margin-left: 50px;
      }
      .play-text {
        font-weight: 700;
      }
    }
  }
  .skill-content {
    background-image: url("~assets/home/bg2.png");
    background-size: cover;
    background-repeat: no-repeat;
    background-position: center center;
    .skill-info {
      width: 800px;
      height: calc(100vh - 170px);
      text-align: left;
      overflow-y: auto;
      background-color: #fff;
      margin: 30px auto 60px;
      padding: 40px 80px;
      border-radius: 10px; /* no */
    }
  }
}
</style>
